<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@	page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<link rel="stylesheet" type="text/css" href="/css/timePicker.css" />
<!-- 验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/formValidator_min.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidator.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidatorRegex.js"></script>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<!-- 時間 -->
<script type="text/javascript" src="/js/jquery.timePicker.js"></script>
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: new Date(), showOn: 'both',numberOfMonths:2,buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#endDate').datepick({minDate: new Date(), showOn: 'both',numberOfMonths:2,buttonImageOnly: true, beforeShow:customRange, buttonImage: '/images/calendar.gif',dateFormat : "yy-mm-dd",yearRange : '-50:+50'});
		function customRange (){
			var startDt = $('#startDate').val(); //起始日
			var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
			return {minDate:endDt}; 
		}
		$("#timeStart").timePicker({step:30, startTime:"00:00", endTime:"23:30"});
		$("#timeEnd").timePicker({step:30, startTime:"00:59", endTime:"23:59"});
		$("#shelfPrice").numeric({allow : "."});
		$("#pickupQty").numeric();
		 $("input[name='chkLimitBuyParam']").click(function(){
				if ( $("#chkLimitBuyParam").attr('checked') ) {
						$("#limitBuyParam").val('Y');
					}else{
						$("#limitBuyParam").val('N');
					}
			});
		$("input[name='chkValidateNumParam']").click(function(){
			if ( $("#chkValidateNumParam").attr('checked') ) {
					$("#validateNumParam").val('Y');
				}else{
					$("#validateNumParam").val('N');
				}
		});

		if ($("#startDate").val() != "") {
			$("#startDate").datepick('disable');
		}
		if ($("#timeStart").val() != "") {
			$("#timeStart").attr("disabled", true);
		}
		
		$("#submit_button").click(function() {
			if($("#promoteNameParam").val().length+chineseCount($("#promoteNameParam").val())>40){
	    		alert("商品促销小标请使用 中文20个字以内");
				return false;
		    }
			if ($("#shelfPrice").val() == "") {
				alert("请输入上架售價");
				return false;
			}
			if ($("#startDate").val() == "") {
				alert("请输入上架起始日期");
				return false;
			}
			if ($("#timeStart").val() == "") {
				alert("请输入上架起始時間");
				return false;
			}
			if ($("#endDate").val() == "") {
				//alert("请输入上架結束日期");
				//return false;
				$("#endDate").val('2999-12-31');
			}
			if ($("#timeEnd").val() == "") {
				//alert("请输入上架結束時間");
				//return false;
				 $("#timeEnd").val('23:59');
			}
			if ( !dateDiff($("#startDate").val() , $("#timeStart").val() ,$("#endDate").val()  , $("#timeEnd").val())){
				 alert("上架結束日期不可大于上架起始日期");
				 return false;
			}
			if ($("#pickupQty").val() == '0'){
				 alert("任选商品可选件数要大于0");
				 return false;
			}
			
		});
	});
	function dateExistCallback(jsonShelfDateExist){
		$("#dateParam").val(jsonShelfDateExist);
	}
	//日期判断,计算天数差的函数
	function dateDiff(sDate1,sTime1, sDate2,sTime2){ //sDate1和sDate2是2002-12-18格式
		 var startDate = new Date(sDate1.split("-")[0],eval(sDate1.split("-")[1])-1,sDate1.split("-")[2],sTime1.split(":")[0],sTime1.split(":")[1],00); 
		 var endDate = new Date(sDate2.split("-")[0],eval(sDate2.split("-")[1])-1,sDate2.split("-")[2],sTime2.split(":")[0],sTime2.split(":")[1],00);
     if ( startDate >= endDate )return false;
     else return true;
	}
	function chineseCount(word){
	    var length=0;
	    for(var cc=0;cc<word.length;cc++){
	       var c = word.charCodeAt(cc);
	      if (!(c>=32&&c<=126)) length++;
	    }
	    return length;
	}
</script>
<h1>N选M商品管理-上下架<br/>
</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<c-rt:if test="${not empty product.productId}">
	<jsp:include page="commonMenu2.jsp"/>
</c-rt:if>
<div class="f-link">
			<a href="${midContextPath}/pickProduct2/shelfSearch.do?productIdParam=${product.productId}">回上下架列表页</a>
			<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/search.do">返回列表页</a>
		</div>
<span class="txt-rd">*</span>表示该项必填
<s:form action="saveShelf.do" method="post">
	<table class="tb-data" width="100%">
		<tr>
			<th>商品名称<br/>(商品编号)</th>
			<td>${product.productName}<br/>${product.productId}</td>
			<th>上架状态</th>
			<td>
				${shelfStatusMenu.options[shelf.shelfStatus].name}
			</td>
		</tr>
			<tr>
			<th>商品促销小标</th>
			<td colspan="3">
				<input type="text" name="promoteNameParam" id="promoteNameParam"  value="${shelf.promoteName}" />上限20个汉字
			</td>
		</tr>
		<tr>
			<th>*上架开始時間</th>
			<td colspan="3">
				<input type="text" name="startDate" id="startDate" size="20" value="<fmt:formatDate value='${shelf.startDate}' pattern='yyyy-MM-dd' />" />
				<c:if test="${not empty shelf.shelfId}">
					<input id="timeStart" name="timeStart" type="text" value="<fmt:formatDate value='${shelf.startDate}' pattern='HH:mm' />" size="10" />
				</c:if>
				<c:if test="${empty shelf.shelfId}">
					<input id="timeStart" name="timeStart" type="text" size="10" />
				</c:if>
			</td>
		</tr>
		<tr>
			<th>上架結束時間</th>
			<td colspan="3">
				<input type="text" name="endDate" id="endDate" size="20" value="<fmt:formatDate value='${shelf.endDate}' pattern='yyyy-MM-dd' />" />
				<c:if test="${not empty shelf.shelfId}">
					<input id="timeEnd" name="timeEnd" type="text" value="<fmt:formatDate value='${shelf.endDate}' pattern='HH:mm' />" size="10" />
				</c:if>
				<c:if test="${empty shelf.shelfId}">
					<input id="timeEnd" name="timeEnd" type="text" size="10" />
				</c:if>
				<span class="txt-gy">上架结束时间不填则表示无限期上架</span>
			</td>
		</tr>
		<tr>
			<th>*上架售價</th>
			<td colspan="3">
				<fmt-rt:formatNumber value="${shelf.shelfPrice}" pattern="#####0.0" var="shelfPrice"/>
				<input type="text" name="shelfPrice" id="shelfPrice" size="10" maxlength="7" value="${shelfPrice}" />
				<span class="txt-gy">上架售价小数点1位数后无条件舍去</span>
			</td>
		</tr>
		<tr>
			<th>* 任选商品可选件数</th>
			<td colspan="3">
				<input type="text" name="pickupQty" id="pickupQty" size="10" maxlength="7" value="${product.pickupQty}" />
			</td>
		</tr>
		<tr>
			<th> 商品贩售限定</th>
			<td colspan="3">
				<input name="chkValidateNumParam" type="checkbox" value="" id="chkValidateNumParam" <c:if test="${shelf.isValidateNum eq 'Y'}">checked="checked"</c:if>/>
				<input name="validateNumParam" type="hidden" value="${shelf.isValidateNum}" id="validateNumParam"/>
				购买时必须输入验证码
				<input name="chkLimitBuyParam" type="checkbox" value="" id="chkLimitBuyParam" <c:if test="${shelf.isLimitBuy eq 'Y'}">checked="checked"</c:if>/>
				<input name="limitBuyParam" type="hidden" value="${shelf.isLimitBuy}" id="limitBuyParam"/>
				单个会员限购一件  <span class="txt-rd">【※储存后将于下一整点后生效】</span>
			</td>
		</tr>
		<tr>
			<td colspan="4">
				<input type="hidden" id="productIdParam" name="productIdParam" value="${product.productId}" />
				<input type="hidden" name="shelfIdParam" value="${shelf.shelfId}" />
				<input type="hidden" id="dateParam" name="dateParam" value="" />
				<input type="submit" id="submit_button" value="发布商品" />
			</td>
		</tr>
	</table>
	<div class="f-link">
			<a href="${midContextPath}/pickProduct2/shelfSearch.do?productIdParam=${product.productId}">回上下架列表页</a>
			<a href="<%=ServerValue.getMidContextPath()%>/pickProduct2/search.do">返回列表页</a>
		</div>
</s:form>